Imports System.Data
Imports DAOMain

Partial Class Accounting_CashAdvanceDetails
    Inherits WebPageCommon

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Call InitVars()

            Dim lkup As New LookUp.FillLookUp
            Dim lfunc As New PolyFunc.ASPFunc
            Dim dao As New CommonDAO
            Dim dt As DataTable = dao.ExecQuery("Select user_name, advisor_name From vw_advisor_mstr Order by advisor_name")

            lfunc.BindDropDown(Advisor_cmb, dt, "advisor_name", "user_name")
            lkup.FillDropDown(Currency_cmb, LookUp.FillLookUp.eLookUpType.other, "CURRENCY")

            Call LoadDetails()

            dao = Nothing
            lkup = Nothing
            dao = Nothing
            dt = Nothing
        End If

        Call SetPageSecurity(divMain)
    End Sub

    Private Sub LoadDetails()
        If Not IsNothing(ViewState("CID")) Then
            Dim cf As New CIMSfunc
            Dim vo As New USER_CASH_ADVANCE_MSTR_VO
            Dim dao As New USER_CASH_ADVANCE_MSTR_DAO

            vo.CASH_ADV_SEQ_CD = ViewState("CID")
            Dim dt As DataTable = dao.Search(vo)

            If dt.Rows.Count > 0 Then
                With dt.Rows(0)
                    Advisor_cmb.SelectedValue = .Item("ADVISOR_CD")
                    Amount_txt.Text = .Item("CASH_ADV_AMT")
                    ARDT_txt.Text = cf.ParseGetDate(.Item("CASH_ADV_DT"))
                    Currency_cmb.SelectedValue = .Item("CASH_ADV_CURR_CD")
                End With
            End If

            vo = Nothing
            dao = Nothing
            cf = Nothing
        End If
    End Sub

    Protected Sub Save_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save_btn.Click
        Dim cf As New CIMSfunc
        Dim vo As New USER_CASH_ADVANCE_MSTR_VO
        Dim dao As New USER_CASH_ADVANCE_MSTR_DAO

        With vo
            .ADVISOR_CD = Advisor_cmb.SelectedValue
            .CASH_ADV_AMT = Amount_txt.Text
            .CASH_ADV_DT = cf.ParseSetDate(ARDT_txt.Text)
            .CASH_ADV_CURR_CD = Currency_cmb.SelectedValue


            Select Case IsNothing(ViewState("CID"))
                Case True
                    .CASH_ADV_SEQ_CD = cf.GetLastID("CASH_ADV_SEQ_CD", "USER_CASH_ADVANCE_MSTR")
                    .CASH_ADV_CREA_BY = Session("UserName")
                    .CASH_ADV_CREA_DT = Now

                    If dao.Create_Record(vo) Then
                        Response.Redirect("~/Accounting/CashAdvance.aspx")
                    End If
                Case False
                    .CASH_ADV_SEQ_CD = ViewState("CID")
                    .CASH_ADV_LAST_UPD_BY = Session("UserName")
                    .CASH_ADV_LAST_UPD_DT = Now

                    If dao.Update(vo) Then
                        Response.Redirect("~/Accounting/CashAdvance.aspx")
                    End If
            End Select
        End With



        cf = Nothing
        vo = Nothing
        dao = Nothing
    End Sub

End Class
